package com.yonyou.lxp.xutils3test.adapter;

import android.content.Context;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;

import com.yonyou.lxp.xutils3test.R;

import org.xutils.x;

import java.util.List;

/**
 * Created by liuxiaopeng on 16/2/4.
 */
public class MyImageAdapter extends BaseAdapter {
    private List list;
    private Context mContext;
    public MyImageAdapter(Context mContext,List list){
        this.list=list;
        this.mContext=mContext;
    }
    @Override
    public int getCount() {
        return list.size();
    }

    @Override
    public Object getItem(int position) {
        return list.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        ViewHoldr viewHoldr;
        if (convertView==null){
            viewHoldr=new ViewHoldr();
            convertView=View.inflate(mContext, R.layout.item_img,null);
            viewHoldr.imageView= (ImageView) convertView.findViewById(R.id.item_img);
            convertView.setTag(viewHoldr);
        }else {
            viewHoldr= (ViewHoldr) convertView.getTag();
        }
        x.image().bind(viewHoldr.imageView, getItem(position).toString());
        return convertView;
    }

    static class ViewHoldr{
        ImageView imageView;
    }

}
